//
//  AppDelegate.m
//  Wedding fantastic
//
//  Created by dllo on 15/6/29.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "AppDelegate.h"

#import "firstPageViewController.h"

#import "RecommendViewController.h"

#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height

@interface AppDelegate ()<UITabBarControllerDelegate>

@end

@implementation AppDelegate
- (void)dealloc {
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [_window release];
    
    // 第一个试图控制器(首页)
    firstPageViewController *firstVC = [[firstPageViewController alloc]init];
    UINavigationController *firstNavC = [[UINavigationController alloc] initWithRootViewController:firstVC];
    // 设置tabbar设置样式
    // 用自己的图片做tabbar的图标
    firstVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageNamed:@"firstPage.png"] tag:1001];
    // 给控制器设置颜色
//    firstVC.view.backgroundColor = [UIColor greenColor];
    
    //抽屉
    DetialBaseViewController *deVC = [[DetialBaseViewController alloc]init];
    deVC.buttonName = @"婚礼策划";
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:deVC];
    SecondViewController *leftMenuViewController = [[SecondViewController alloc] init];
//    ThirdViewController *rightMenuViewController = [[ThirdViewController alloc] init];
    
    RESideMenu *sideMenuViewController = [[RESideMenu alloc] initWithContentViewController:navigationController leftMenuViewController:leftMenuViewController rightMenuViewController:nil];
    sideMenuViewController.backgroundImage = [UIImage imageNamed:@"2170869_113308950000_2"];
    sideMenuViewController.menuPreferredStatusBarStyle = 1; // UIStatusBarStyleLightContent
    sideMenuViewController.delegate = self;
    sideMenuViewController.contentViewShadowColor = [UIColor blackColor];
    sideMenuViewController.contentViewShadowOffset = CGSizeMake(0, 0);
    sideMenuViewController.contentViewShadowOpacity = 0.6;
    sideMenuViewController.contentViewShadowRadius = 12;
    sideMenuViewController.contentViewShadowEnabled = YES;
    

    // 第二个试图控制器(分类)
    CategoriesViewController *secVC = [[CategoriesViewController alloc]init];
    UINavigationController *secNavC = [[UINavigationController alloc] initWithRootViewController:sideMenuViewController];
    secNavC.navigationBarHidden = YES;
    // 设置tabbar设置样式
    // 用自己的图片做tabbar的图标
    sideMenuViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"分类" image:[UIImage imageNamed:@"classify.png"] tag:1002];
//    // 给控制器设置颜色
//    sideMenuViewController.view.backgroundColor = [UIColor cyanColor];
//    // 给控制设标题
//    sideMenuViewController.title = @"分类";
    
    // 第三个试图控制器(推荐)
    RecommendViewController *thirdVC = [[RecommendViewController alloc]init];
    UINavigationController *thirdNavC = [[UINavigationController alloc] initWithRootViewController:thirdVC];
    // 设置tabbar设置样式
    // 用自己的图片做tabbar的图标
    thirdVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"推荐" image:[UIImage imageNamed:@"recommend1"] tag:1003];
    // 给控制设标题
    
    // 第四个试图控制器(我的)
    MineViewController *fourVC = [[MineViewController alloc]init];
    UINavigationController *fourNavC = [[UINavigationController alloc] initWithRootViewController:fourVC];
    // 设置tabbar设置样式
    // 用自己的图片做tabbar的图标
    fourVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:[UIImage imageNamed:@"myself.png"] tag:1003];
    // 给控制器设置颜色
    fourVC.view.backgroundColor = [UIColor purpleColor];
    // 给控制设标题
    fourVC.title = @"我的";
    
    
    
    
    // 创建一个tabbar控制器
    UITabBarController *tab = [[UITabBarController alloc] init];
    // 把导航控制器放到tabbar控制器中
    tab.viewControllers = [NSArray arrayWithObjects:firstNavC, secNavC, thirdNavC, fourNavC, nil];
    // 把tabbar控制器设为窗口的根控制器
    self.window.rootViewController = tab;
    
    // tabbar来设置外观
    // 设置不透明
    tab.tabBar.translucent = NO;
    // 设置代理人
    tab.delegate = self;
    tab.tabBar.tintColor = [UIColor brownColor];
    
    // 内存管理
    [firstVC release];
    [firstNavC release];
    [secVC release];
    [secNavC release];
    [thirdVC release];
    [thirdNavC release];
    [fourVC release];
    [fourNavC release];
    
    
//    self.splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
//    self.splashView.image = [UIImage imageNamed:@"Default.png"];
//    [self.window addSubview:self.splashView];
//    [self.window bringSubviewToFront:self.splashView];
//    [UIView beginAnimations:nil context:nil];
//    [UIView setAnimationDuration:3];
//    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.window cache:YES];
//    [UIView setAnimationDelegate:self];
//    self.splashView.alpha = 0.0;
//    self.splashView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
//    [UIView commitAnimations];
//    [_splashView release];
    
    return YES;
}

#pragma mark -
#pragma mark RESideMenu Delegate

- (void)sideMenu:(RESideMenu *)sideMenu willShowMenuViewController:(UIViewController *)menuViewController
{
    NSLog(@"willShowMenuViewController: %@", NSStringFromClass([menuViewController class]));
}

- (void)sideMenu:(RESideMenu *)sideMenu didShowMenuViewController:(UIViewController *)menuViewController
{
    NSLog(@"didShowMenuViewController: %@", NSStringFromClass([menuViewController class]));
}

- (void)sideMenu:(RESideMenu *)sideMenu willHideMenuViewController:(UIViewController *)menuViewController
{
    NSLog(@"willHideMenuViewController: %@", NSStringFromClass([menuViewController class]));
}

- (void)sideMenu:(RESideMenu *)sideMenu didHideMenuViewController:(UIViewController *)menuViewController
{
    NSLog(@"didHideMenuViewController: %@", NSStringFromClass([menuViewController class]));
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
